package com.smedi.ismedi.personnel.core.domain.aggregatemodel.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smedi.ismedi.personnel.core.application.query.PersonSyncQueryService;
import com.smedi.ismedi.personnel.core.application.query.vo.InternalPersonAssignmentVo;
import com.smedi.ismedi.personnel.core.application.query.vo.PersonSyncFromImisVo;
import com.smedi.ismedi.personnel.core.infrastructure.enumerate.GenderEnum;
import com.smedi.ismedi.personnel.core.port.adapter.persistence.mybatis.mapper.PersonSyncFromImisMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @Author: xulinjun
 * @Date: 2021-6-16 19:39
 */
@Slf4j
@Service
@AllArgsConstructor
public class PersonSyncQueryServiceImpl implements PersonSyncQueryService {
    private final PersonSyncFromImisMapper personSyncFromImisMapper;

    @Override
    public IPage selectPersonSyncVoPagination(Long offset, Long pageSize, String lastName, String employeeNum, String hrJob, Long subOrganizationId) {
        Page<InternalPersonAssignmentVo> page = new Page<>(offset, pageSize);
        page.addOrder(new OrderItem().ascs("org_code", "employee_num"));

        IPage<PersonSyncFromImisVo> pagination = personSyncFromImisMapper.selectPersonSyncVoPagination(page, lastName, employeeNum, hrJob, subOrganizationId);
        pagination.getRecords().stream().forEach(i -> {
            i.setGenderMeaning(GenderEnum.getName(i.getGender()));
        });
        return pagination;
    }
}
